package hu.example.munka_count.model;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DataBase extends SQLiteOpenHelper {
	static final String dbName = "date";
	static final int dbVersion = 3;
	static final String colID = "id";
	static final String colCurrDate = "curr_date";
	static final String colStartMills = "start_mills";
	static final String colEndMills = "end_mills";

	// Database creation sql statement
	private static final String DATABASE_CREATE = "create table " + dbName
			+ "(" + colID + " integer primary key autoincrement, "
			+ colCurrDate + " text not null, "
			+ colStartMills + " text not null, "
			+ colEndMills + " text);";

	public DataBase(Context context) {
		super(context, dbName, null, dbVersion);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		 Log.i(database.getClass().toString(), "onCreate");
		 database.execSQL(DATABASE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.i(db.getClass().toString(),
		        "Upgrading database from version " + oldVersion + " to "
		            + newVersion + ", which will destroy all old data");
		    db.execSQL("DROP TABLE IF EXISTS " + dbName);
		    onCreate(db);

	}

}
